"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.guiOptions = exports.guiTestColor = exports.guiTestRotate = exports.guiTestScale = exports.guiTestPosition = exports.initGUI = void 0;
/*
 * @Author: hongbin
 * @Date: 2022-08-05 08:36:59
 * @LastEditors: hongbin
 * @LastEditTime: 2023-09-30 10:08:47
 * @Description:gui调试
 */
var dat_gui_1 = require("dat.gui");
//TODO 整理成class
/**
 * 初始化GUI调试工具
 */
var initGUI = function (name) {
    var _a;
    if (name === void 0) { name = "GUI console"; }
    if (process.env.NODE_ENV === "development") {
        //热更新会创建多个实例 删除之前的实例
        var oldInst = document.querySelector(".dg.main");
        (_a = oldInst === null || oldInst === void 0 ? void 0 : oldInst.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(oldInst);
        // console.log("del", );
    }
    //   在next中要这样使用GUI
    // const { GUI } = require("dat.gui");
    var gui = new dat_gui_1.GUI({ name: name });
    window.gui = gui;
    // window.gui.hide();
    return gui;
};
exports.initGUI = initGUI;
var vectorKeys = ["x", "y", "z"];
var guiTestPosition = function (mesh, range, name, other) {
    if (range === void 0) { range = 20; }
    var meshName = mesh.name, type = mesh.type, uuid = mesh.uuid, position = mesh.position;
    // 新建一个文件夹
    var folder = window.gui.addFolder(name || meshName || type + uuid.substring(0, 5));
    setTimeout(function () {
        for (var _i = 0, vectorKeys_1 = vectorKeys; _i < vectorKeys_1.length; _i++) {
            var key = vectorKeys_1[_i];
            folder
                .add(position, key, position[key] - range, position[key] + range)
                .onChange(window.render);
        }
        other && other(folder);
    });
    return folder;
};
exports.guiTestPosition = guiTestPosition;
var guiTestScale = function (mesh, range, name) {
    if (range === void 0) { range = 20; }
    var meshName = mesh.name, type = mesh.type, uuid = mesh.uuid, scale = mesh.scale;
    // 新建一个文件夹
    var folder = window.gui.addFolder((name || meshName || type + uuid.substring(0, 5)) + "scale");
    setTimeout(function () {
        for (var _i = 0, vectorKeys_2 = vectorKeys; _i < vectorKeys_2.length; _i++) {
            var key = vectorKeys_2[_i];
            folder
                .add(scale, key, scale[key] - range, scale[key] + range)
                .onChange(window.render);
        }
    });
    return folder;
};
exports.guiTestScale = guiTestScale;
var guiTestRotate = function (mesh, range, name) {
    if (range === void 0) { range = 3.14; }
    var meshName = mesh.name, type = mesh.type, uuid = mesh.uuid, rotation = mesh.rotation;
    // 新建一个文件夹
    var folder = window.gui.addFolder((name || meshName + uuid.substring(0, 3) || type + uuid.substring(0, 3)) +
        "rotate");
    setTimeout(function () {
        for (var _i = 0, vectorKeys_3 = vectorKeys; _i < vectorKeys_3.length; _i++) {
            var key = vectorKeys_3[_i];
            folder
                .add(rotation, key, rotation[key] - range, rotation[key] + range)
                .onChange(window.render);
        }
    });
    return folder;
};
exports.guiTestRotate = guiTestRotate;
var guiTestColor = function (color) {
    var params = { color: color };
    return window.gui.addColor(params, "color");
};
exports.guiTestColor = guiTestColor;
var guiOptions = function (options, defaultValue, name) {
    var _a;
    return window.gui.add((_a = {}, _a[name] = defaultValue, _a), name).options(options);
};
exports.guiOptions = guiOptions;
